<?php if (!defined('BASEPATH')) exit('No direct script access allowed');?>

<div class="col-lg-12">
    <?php
    echo form_open(base_url($this->config->item('area_admin') . '/servico/salvar'), 'id="editar_servico"'); 
    
    echo form_hidden('id', (isset($servico->id))? $servico->id: set_value('id'));
    
    echo form_input(array('name' => 'base_url','type' => 'hidden','id' => 'base_url','value' => base_url($this->config->item('area_admin'))
                        ));

    ?>
    
    <div class="row">
        <div class="form-group col-lg-6">
            <?php
            echo form_label('Titulo *');
            echo form_input('titulo', (isset($servico->titulo)? $servico->titulo: set_value('titulo')), 'id="titulo" class="form-control"');
            echo form_error('titulo');
            ?>
        </div>
        
        
    </div>
    <div class="row">
        <div class="form-group col-lg-6">
            <?php 
            
            
            echo form_label('Progresso *');
            if(empty($servico->id)){
                $progresso_servico = $this->config->item('progresso_servico_cad');
            }
            else{
                 $progresso_servico = $this->config->item('progresso_servico');
            }

            echo form_dropdown('progresso',$progresso_servico,(isset($servico->progresso)? $servico->progresso: set_value('progresso')),'class="form-control" id="progresso"');
            echo form_error('status');
            ?>
        </div> 
        
    </div>
    <div class="row">
       <?php
           if(!empty($servico->id))
           {
        ?>
        <div class="form-group col-lg-4" id="div-data-inicio">
            
            <label for="data_inicio" class="">Data Inicio</label>
                
            <span class="" style="display: none;" id="data_inicio_span">&nbsp;*</span>
            <?php
           
            echo form_input('data_inicio', ($servico->data_inicio!='0000-00-00' && (isset($servico->data_inicio))? get_data_banco($servico->data_inicio) : set_value('data_inicio')), 'id="data_inicio" class="form-control mask-data"');
            echo form_error('data_inicio');
            ?>
            <label for="data_inicio" class="" style="display: none;" id="msg_verifica_data_inicio">&nbsp;Data obrigatória.</label>
        </div>
        <?php
           }
        ?>
         <div class="form-group col-lg-4">
            <?php
            
            
            
            echo form_label('Data Vencimento *');
            echo form_input('data_vencimento', (isset($servico->data_venc)? get_data_banco($servico->data_venc) : set_value('data_vencimento')), 'id="data_vencimento" class="form-control mask-data"');
            echo form_error('data_vencimento');
            ?>
        </div>
        <?php
           if(!empty($servico->id))
           {
        ?>
            <div class="form-group col-lg-4 " id="div-data-fim">
                <label for="data_fim" class="">Data final</label>
                
                <span class="" style="display: none;" id="data_fim_span">&nbsp;*</span>
                <?php
                echo form_input('data_fim', ($servico->data_fim!='0000-00-00' && (isset($servico->data_fim))? get_data_banco($servico->data_fim): set_value('data_fim')), 'id="data_fim" class="form-control mask-data"');
                echo form_error('data_fim');
                ?>
                <label for="data_fim" class="" style="display: none;" id="msg_verifica_data_fim">&nbsp;</label>
            </div>
        <?php
           }
        ?>
        
        
    </div>
    <div class="row">
        <div class="form-group col-lg-2">
                <?php 

                        echo form_label('Setor *');
    
                        if(!_admin())
                        {
                            $setores_gerente=$this->session->userdata('setores');
                            
                            foreach($setores as $key=>$value)
                            {
                                foreach ($setores_gerente as $sg)
                                {
                                    if($key== $sg)
                                    {
                                        $opcoes[$key] = $value;
                                    }
                                }
                            }
                        }
                        else
                        {
                            $opcoes = $setores;
                        }
                        
                        $opcoes[''] = 'Selecione';

                        echo form_dropdown('setor', $opcoes, (isset($servico->setor_id) ? $servico->setor_id : set_value('setor')), ' id="setor" class="form-control"');
                ?>
        </div>
        <div class="form-group col-lg-6">
            <?php
                echo '<span id="loader" style="display:none;">' . img(base_url('assets/img/loader.gif')) . '</span>';
                
                echo form_label('Funcionarios');
            ?>
            <div class="exibe_func">
                <?php
                (isset($servico->id))? $id =  $servico->id:$id =  set_value('id');
                    if($id){
                        $verifica_checked = function($funcionarios,$funcionario_id){
                            
                            
                            foreach ($funcionarios as $f){
                                if($f === $funcionario_id ){
                                    return true;
                                }
                            }
                            return false;
                        };
                        
                        foreach ($funcionarios as $f){
            
                            
                                    
                            $atributos = array(
                                        'name'    => 'funcionarios[]',
                                        'id'      => 'f_' . $f->id,
                                        'value'   => $f->id,
                                        'checked' => $verifica_checked($servico->funcionarios, $f->id)
                                          );

                            echo '<div class="checkbox"><label>' . form_checkbox($atributos) . '&nbsp;' . $f->nome . '</label></div>';

                        }
                    }
                
                
                ?>
                
                
            </div>         
        </div>
    </div>
    
    <div class="row">
        <div class="form-group col-lg-6">
            <?php
            echo form_label('Descricao *');
            echo form_textarea('descricao', (isset($servico->descricao)? $servico->descricao: set_value('descricao')), 'id="descricao" class="form-control"');
            echo form_error('descricao');
            ?>
        </div> 
        
    </div>
    

    
    
    <div class="row" style="padding-top: 20px;">
        <div class="form-group col-lg-6">
            <?php 

            echo form_submit('salvar','Salvar', 'class="btn btn-primary"');

            echo '&nbsp;' . form_button('cancelar','Cancelar', 'class="btn btn-danger btn_cancelar"');
            ?>
        </div>
    </div>
    
    <?php echo form_close(); ?>
</div> 